<?php
declare (strict_types = 1);
namespace app\model\table\config;

use app\model\BaseModel;
use app\model\MyException;

class ConfigGlobal extends BaseModel
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'app_config_global';

    // 该表是否缓存到redis
    public $tableToRedis = true;

    // 该表缓存到redis的策略
    public $tableToRedisKey = ['name'];

    // 不允许通过add方法修改的字段
    public $notAllowAddColumn = [];

    public function findValue($name)
    {
        try {
            $obj = ConfigGlobal::instance()->findOne(['name'=>$name], true);
            if(empty($obj))
            {
                throw new MyException("系统配置不存在");
            }
            if($obj['is_json'] == 1){
                return json_decode($obj['value'], true);
            }else{
                return $obj['value'];
            }
        } catch (MyException $e) {
            echo $e->toJson();
        }
    }
}
